﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace TempEmployees.Web
{
    [Serializable]
    public class SelectedValueObject
    {
        //
        // value

        private string m_value;

        //
        // c'tor

        public SelectedValueObject(string value)
        {
            m_value = value;
        }

        public override string ToString()
        {
            return m_value.ToString();
        }

        //
        // get

        public static implicit operator string(SelectedValueObject valueObj)
        {
            return valueObj.m_value;
        }
        public static implicit operator int(SelectedValueObject valueObj)
        {
            try
            { return int.Parse(valueObj.m_value); }
            catch
            { return int.MinValue; } // return null will force the return type to be 'int?' - don't want that
        }
        public static implicit operator short(SelectedValueObject valueObj)
        {
            try
            { return short.Parse(valueObj.m_value); }
            catch
            { return short.MinValue; } // return null will force the return type to be 'short?' - don't want that
        }
        public static implicit operator decimal(SelectedValueObject valueObj)
        {
            try
            { return decimal.Parse(valueObj.m_value); }
            catch
            { return decimal.MinValue; } // return null will force the return type to be 'short?' - don't want that
        }

        //
        // set

        public static implicit operator SelectedValueObject(string value)
        {
            return new SelectedValueObject(value);
        }
        public static implicit operator SelectedValueObject(int value)
        {
            return new SelectedValueObject(value.ToString());
        }
        public static implicit operator SelectedValueObject(short value)
        {
            return new SelectedValueObject(value.ToString());
        }
        public static implicit operator SelectedValueObject(decimal value)
        {
            return new SelectedValueObject(value.ToString());
        }
    }
}
